// pages/forum/forum.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    use: 0,
    forumID: -1,
    ad: null,
    forum: null,
    forumLeaderInfo: null
  },
  goSearch() {
    wx.navigateTo({
      url: '/pages/search/search',
      fail: () => {
        wx.showToast({
          title: '页面加载失败',
          icon: "error"
        })
      }
    })
  },
  change(e) {
    let index = e.target.dataset.index
    this.setData({
      use: index
    })
  },
  cShowModel(title, content) {
    wx.showModal({
      title: title,
      content: content,
      showCancel: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let forumID = options.forumID
    let host = getApp().data.serverHost
    let token = wx.getStorageSync('token')
    if (this.data.ad == null) {
      wx.request({
        url: host + '/api/ad/get',
        method: "GET",
        header: {
          "Authorization": "Bearer " + token
        },
        success: (e) => {
          let response = e.data
          if (response.code == 200) {
            this.setData({
              ad: response.data
            })
          } else {
            this.cShowModel('小程序提示', '网络请求错误，请稍后再试')
          }
        },

        fail: (e) => {

        }
      })
    }
    if (this.data.forumLeaderInfo == null || this.data.forum == null) {
      wx.request({
        url: host + "/api/rs-af/detail?forumID=" + forumID,
        method:"GET",
        header:{
          "Authorization":"Bearer "+token
        },
        success:(e)=>{
          let response=e.data
          if(response.code==200){
            this.setData({
              forum:response.data.forum,
              forumLeaderInfo:response.data.forumLeaderInfo
            })
          }else{
            this.cShowModel('小程序提示','网络出现错误')
          }
        }
      })
    }
  },
  goMoveDetails(e) {
    wx.navigateTo({
      url: '/pages/forum-details/forum-details',
      fail: () => {
        wx.showToast({
          title: '页面加载失败',
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})